﻿using System;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace IFD2
{
    public partial class ctlSeatMatching : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void compare_Class(string op_airline, string op_flt_no, DateTime flt_date)
        {
            int ret_code;
            StringBuilder buf = new StringBuilder();
            //buf.Append("<table><tr><th colspan='3'>Aircraft</th><th colspan='3'>Tickets</th></tr>");
            litClass.Text = "";
            SqlCommand cmd = new SqlCommand();
            DataTable dtRet = new DataTable();
            try
            {
                cmd.CommandText = "bll_flt_get_class_matching";
                SqlParameter para = cmd.Parameters.AddWithValue("@op_airline", op_airline);
                para = cmd.Parameters.AddWithValue("@op_flt_no", op_flt_no);
                para = cmd.Parameters.AddWithValue("@flt_date", flt_date);
                para = cmd.Parameters.AddWithValue("@user_airport", Session["DCS_AIRPORT"].ToString());
                para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
                para = cmd.Parameters.AddWithValue("@office", Session["OFFICE"].ToString());
                para = cmd.Parameters.AddWithValue("@user_airline", Session["AIRLINE"].ToString());

                ret_code = TinyDAL.Exec(ref cmd, ref dtRet);
                if (ret_code == 0)
                {
                    //lblErrStat.Text = "Done.";
                    ret_code = 0;
                    foreach (DataRow rows in dtRet.Rows)
                    {
                        buf.Append("<tr><td>" + rows["a_ori_airport"].ToString().TrimEnd() + "-" + rows["a_des_airport"].ToString() + "</td><td width='20px' align='center'>" + rows["a_class"].ToString()
                            + "</td><td width='80px' align='center'>" + rows["a_total"].ToString() + "</td>");
                        buf.Append("<td>" + rows["t_ori_airport"].ToString().TrimEnd() + "-" + rows["t_des_airport"].ToString() + "</td><td width='20px' align='center'>" + rows["t_class"].ToString()
                            + "</td><td width='80px' align='center'>" + rows["t_total"].ToString() + "</td></tr>");
                    }
                    //buf.Append("</table>");
                    litClass.Text = buf.ToString();
                }
                else if (ret_code == 1)
                    litClass.Text = "Unauthorized office!";
                else if (ret_code == 51)
                    litClass.Text = "Unconcerned flight!";
                else
                    litClass.Text = "Error:" + ret_code.ToString();
            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    litClass.Text = ex.Message;
                else
                    litClass.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
            }
        }

        protected void compare_Seat(string op_airline, string op_flt_no, DateTime flt_date)
        {
            int ret_code;
            StringBuilder buf = new StringBuilder();
            //buf.Append("<table><tr><th colspan='3'>Aircraft</th><th colspan='3'>Tickets</th></tr>");
            litSeatType.Text = "";
            SqlCommand cmd = new SqlCommand();
            DataTable dtRet = new DataTable();
            try
            {
                cmd.CommandText = "bll_flt_get_seat_type_matching";
                SqlParameter para = cmd.Parameters.AddWithValue("@op_airline", op_airline);
                para = cmd.Parameters.AddWithValue("@op_flt_no", op_flt_no);
                para = cmd.Parameters.AddWithValue("@flt_date", flt_date);
                para = cmd.Parameters.AddWithValue("@user_airport", Session["DCS_AIRPORT"].ToString());
                para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
                para = cmd.Parameters.AddWithValue("@office", Session["OFFICE"].ToString());
                para = cmd.Parameters.AddWithValue("@user_airline", Session["AIRLINE"].ToString());

                ret_code = TinyDAL.Exec(ref cmd, ref dtRet);
                if (ret_code == 0)
                {
                    //lblErrStat.Text = "Done.";
                    ret_code = 0;
                    foreach (DataRow rows in dtRet.Rows)
                    {
                        buf.Append("<tr><td>" + rows["a_ori_airport"].ToString().TrimEnd() + "-" + rows["a_des_airport"].ToString() + "</td><td width='20px' align='center'>" + rows["a_seat_type"].ToString()
                            + "</td><td width='80px' align='center'>" + rows["a_total"].ToString() + "</td>");
                        buf.Append("<td>" + rows["t_ori_airport"].ToString().TrimEnd() + "-" + rows["t_des_airport"].ToString() + "</td><td width='20px' align='center'>" + rows["t_seat_type"].ToString()
                            + "</td><td width='80px' align='center'>" + rows["t_total"].ToString() + "</td></tr>");
                    }
                    //buf.Append("</table>");
                    litSeatType.Text = buf.ToString();
                }
                else if (ret_code == 1)
                    litSeatType.Text = "Unauthorized office!";
                else if (ret_code == 51)
                    litSeatType.Text = "Unconcerned flight!";
                else
                    litSeatType.Text = "Error:" + ret_code.ToString();
            }
            catch (Exception ex)
            {
                if (Application["DEBUG"].ToString() == "1")
                    litSeatType.Text = ex.Message;
                else
                    litSeatType.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
            }
        }

        //protected void compare_AcClass(string op_airline,string op_flt_no,DateTime flt_date)
        //{
        //    int ret_code;
        //    StringBuilder buf = new StringBuilder();
        //    buf.Append("<table>");
        //    litAcClass.Text = "";
        //    SqlCommand cmd = new SqlCommand();
        //    DataTable dtRet = new DataTable();
        //    try
        //    {
        //        cmd.CommandText = "usp_get_flt_ac_class_compare";
        //        SqlParameter para = cmd.Parameters.AddWithValue("@op_airline", op_airline);
        //        para = cmd.Parameters.AddWithValue("@op_flt_no", op_flt_no);
        //        para = cmd.Parameters.AddWithValue("@flt_date", flt_date);
        //        para = cmd.Parameters.AddWithValue("@user_airport", Session["DCS_AIRPORT"].ToString());
        //        para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
        //        para = cmd.Parameters.AddWithValue("@office", Session["OFFICE"].ToString());
        //        para = cmd.Parameters.AddWithValue("@user_airline", Session["AIRLINE"].ToString());

        //        ret_code = TinyDAL.Exec(ref cmd, ref dtRet);
        //        if (ret_code == 0)
        //        {
        //            //lblErrStat.Text = "Done.";
        //            ret_code = 0;
        //            foreach (DataRow rows in dtRet.Rows)
        //            {
        //                buf.Append("<tr><td width='33%' align='center'>" + rows["ori_airport"].ToString().TrimEnd() + "-" + rows["des_airport"].ToString() + "</td><td width='20px' align='center'>" + rows["class"].ToString()
        //                    + "</td><td width='25%' align='center'>" + rows["total"].ToString() + "</td></tr>");
        //            }
        //            buf.Append("</table>");
        //            litAcClass.Text = buf.ToString();
        //        }
        //        else if (ret_code == 1)
        //            litAcClass.Text = "Unauthorized office!";
        //        else if (ret_code == 51)
        //            litAcClass.Text = "Unconcerned flight!";
        //        else
        //            litAcClass.Text = "Error:" + ret_code.ToString();
        //    }
        //    catch (Exception ex)
        //    {
        //        if (Application["DEBUG"].ToString() == "1")
        //            litAcClass.Text = ex.Message;
        //        else
        //            litAcClass.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
        //    }
        //}

        //protected void compare_TktClass(string op_airline,string op_flt_no,DateTime flt_date)
        //{
        //    int ret_code;
        //    StringBuilder buf = new StringBuilder();
        //    buf.Append("<table>");
        //    litTktClass.Text = "";
        //    SqlCommand cmd = new SqlCommand();
        //    DataTable dtRet = new DataTable();
        //    try
        //    {
        //        cmd.CommandText = "usp_get_flt_tkt_class_compare";
        //        SqlParameter para = cmd.Parameters.AddWithValue("@op_airline", op_airline);
        //        para = cmd.Parameters.AddWithValue("@op_flt_no", op_flt_no);
        //        para = cmd.Parameters.AddWithValue("@flt_date", flt_date);
        //        para = cmd.Parameters.AddWithValue("@user_airport", Session["DCS_AIRPORT"].ToString());
        //        para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
        //        para = cmd.Parameters.AddWithValue("@office", Session["OFFICE"].ToString());
        //        para = cmd.Parameters.AddWithValue("@user_airline", Session["AIRLINE"].ToString());

        //        ret_code = TinyDAL.Exec(ref cmd, ref dtRet);
        //        if (ret_code == 0)
        //        {
        //            //lblErrStat.Text = "Done.";
        //            ret_code = 0;
        //            foreach (DataRow rows in dtRet.Rows)
        //            {
        //                buf.Append("<tr><td width='33%' align='center'>" + rows["ori_airport"].ToString() + "-" + rows["des_airport"].ToString() + "</td><td width='20px' align='center'>" + rows["class"].ToString()
        //                    + "</td><td width='25%' align='center'>" + rows["total"].ToString() + "</td></tr>");
        //            }
        //            buf.Append("</table>");
        //            litTktClass.Text = buf.ToString();
        //        }
        //        else if (ret_code == 1)
        //            litTktClass.Text = "Unauthorized office!";
        //        else if (ret_code == 51)
        //            litTktClass.Text = "Unconcerned flight!";
        //        else
        //            litTktClass.Text = "Error:" + ret_code.ToString();
        //    }
        //    catch (Exception ex)
        //    {
        //        if (Application["DEBUG"].ToString() == "1")
        //            litTktClass.Text = ex.Message;
        //        else
        //            litTktClass.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
        //    }
        //}

        //protected void compare_AcSeat(string op_airline,string op_flt_no,DateTime flt_date)
        //{
        //    int ret_code;
        //    StringBuilder buf = new StringBuilder();
        //    buf.Append("<table>");
        //    litAcSeat.Text = "";
        //    SqlCommand cmd = new SqlCommand();
        //    DataTable dtRet = new DataTable();
        //    try
        //    {
        //        cmd.CommandText = "usp_get_flt_ac_seat_compare";
        //        SqlParameter para = cmd.Parameters.AddWithValue("@op_airline", op_airline);
        //        para = cmd.Parameters.AddWithValue("@op_flt_no", op_flt_no);
        //        para = cmd.Parameters.AddWithValue("@flt_date", flt_date);
        //        para = cmd.Parameters.AddWithValue("@user_airport", Session["DCS_AIRPORT"].ToString());
        //        para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
        //        para = cmd.Parameters.AddWithValue("@office", Session["OFFICE"].ToString());
        //        para = cmd.Parameters.AddWithValue("@user_airline", Session["AIRLINE"].ToString());

        //        ret_code = TinyDAL.Exec(ref cmd, ref dtRet);
        //        if (ret_code == 0)
        //        {
        //            //lblErrStat.Text = "Done.";
        //            ret_code = 0;
        //            foreach (DataRow rows in dtRet.Rows)
        //            {
        //                buf.Append("<tr><td width='33%' align='center'>" + rows["ori_airport"].ToString() + "-" + rows["des_airport"].ToString() + "</td><td width='20px' align='center'>" + rows["seat_type"].ToString()
        //                    + "</td><td width='25%' align='center'>" + rows["total"].ToString() + "</td></tr>");
        //            }
        //            buf.Append("</table>");
        //            litAcSeat.Text = buf.ToString();
        //        }
        //        else if (ret_code == 1)
        //            litAcSeat.Text = "Unauthorized office!";
        //        else if (ret_code == 51)
        //            litAcSeat.Text = "Unconcerned flight!";
        //        else
        //            litAcSeat.Text = "Error:" + ret_code.ToString();
        //    }
        //    catch (Exception ex)
        //    {
        //        if (Application["DEBUG"].ToString() == "1")
        //            litAcSeat.Text = ex.Message;
        //        else
        //            litAcSeat.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
        //    }
        //}

        //protected void compare_TktSeat(string op_airline,string op_flt_no,DateTime flt_date)
        //{
        //    int ret_code;
        //    StringBuilder buf = new StringBuilder();
        //    buf.Append("<table>");
        //    litTktSeat.Text = "";
        //    SqlCommand cmd = new SqlCommand();
        //    DataTable dtRet = new DataTable();
        //    try
        //    {
        //        cmd.CommandText = "usp_get_flt_tkt_seat_compare";
        //        SqlParameter para = cmd.Parameters.AddWithValue("@op_airline", op_airline);
        //        para = cmd.Parameters.AddWithValue("@op_flt_no", op_flt_no);
        //        para = cmd.Parameters.AddWithValue("@flt_date", flt_date);
        //        para = cmd.Parameters.AddWithValue("@user_airport", Session["DCS_AIRPORT"].ToString());
        //        para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
        //        para = cmd.Parameters.AddWithValue("@office", Session["OFFICE"].ToString());
        //        para = cmd.Parameters.AddWithValue("@user_airline", Session["AIRLINE"].ToString());

        //        ret_code = TinyDAL.Exec(ref cmd, ref dtRet);
        //        if (ret_code == 0)
        //        {
        //            //lblErrStat.Text = "Done.";
        //            ret_code = 0;
        //            foreach (DataRow rows in dtRet.Rows)
        //            {
        //                buf.Append("<tr><td width='33%' align='center'>" + rows["ori_airport"].ToString() + "-" + rows["des_airport"].ToString() + "</td><td width='20px' align='center'>" + rows["seat_type"].ToString()
        //                    + "</td><td width='25%' align='center'>" + rows["total"].ToString() + "</td></tr>");
        //            }
        //            buf.Append("</table>");
        //            litTktSeat.Text = buf.ToString();
        //        }
        //        else if (ret_code == 1)
        //            litTktSeat.Text = "Unauthorized office!";
        //        else if (ret_code == 51)
        //            litTktSeat.Text = "Unconcerned flight!";
        //        else
        //            litTktSeat.Text = "Error:" + ret_code.ToString();
        //    }
        //    catch (Exception ex)
        //    {
        //        if (Application["DEBUG"].ToString() == "1")
        //            litTktSeat.Text = ex.Message;
        //        else
        //            litTktSeat.Text = "Unexpected error! Please recheck the input/output data first. If the error appears again, contact adminstrator with your operating details please.";
        //    }
        //}

        public void compare(string op_airline, string op_flt_no, DateTime flt_date)
        {
            compare_Class(op_airline, op_flt_no, flt_date);
            compare_Seat(op_airline, op_flt_no, flt_date);

            //compare_AcClass(op_airline,op_flt_no,flt_date);
            //compare_TktClass(op_airline,op_flt_no,flt_date);
            //compare_AcSeat(op_airline,op_flt_no,flt_date);
            //compare_TktSeat(op_airline,op_flt_no,flt_date);
        }
    }
}